<!-- 设置日报渠道显示规则 -->
<template>
  <div class="summary_page">
    <dynamic-header ref="dynamicHeader" @fieldCancel="fieldCancel" @headUpdate="headUpdate"
      :sourcedata="sourcedata" :targetdata="targetdata" :infoText='infoText' dataAll='true'
      :iconLock='true' :tipsFlag='true'>
    </dynamic-header>
  </div>
</template>

<script>
  import dailyApi from '@/biz/buildingHome/daily'
  import moment from 'moment'
  import dynamicHeader from '@/components/dynamicHeader.vue'
  export default {
    components: { dynamicHeader },
    data() {
      return {
        tipsFlag: false,
        sourcedata: [],
        targetdata: [],
        infoText: {
          text1: '设置日报渠道显示规则',
          text2: '未在日报中显示',
          text3: '在日报中显示',
          bottomText: '说明：你至多可设置5个渠道在日报首页锁定并调整排序',
          topTips: `您可将需要在“案场日报”中显示的渠道添加至列表右侧。在右侧列表中，<span style='color:red'>你至多可设置5个渠道在日报首页锁定并调整排序</ span>`
        },
      }
    },
    methods: {
      show(currentDate) {
        let params = {
          buildingId: this.$dt.buildInfo().housesId,
          date: currentDate
        }
        dailyApi.findDailyChannel(params).then(res => {
          res.hasConfigChannelList.forEach((item) => {
            item.lock = item.hasLock
            item.iconLock = true
            item.fieldValue = item.channelName
            item.createTimes = moment(item.channelCreateTime).valueOf()
          })
          res.unConfigChannelList.forEach((item) => {
            item.lock = false
            item.iconLock = false
            item.fieldValue = item.channelName
            item.createTimes = moment(item.channelCreateTime).valueOf()
          })
          this.targetdata = res.hasConfigChannelList
          this.sourcedata = res.unConfigChannelList
        })
        this.$refs.dynamicHeader.show()
      },
      fieldCancel() {
        this.$refs.dynamicHeader.hide()
      },
      headUpdate(val) {
        let channelList = []
        val.targetList && val.targetList.forEach((item, index) => {
          channelList.push({
            hasLock: item.lock,
            serialNo: index,
            channelId: item.channelId
          })
        })
        let params = {
          buildingId: this.$dt.buildInfo().housesId,
          channelList,
        }
        dailyApi.updateLockDailyChannel(params).then((res) => {
          this.$$emit('changeChannel')
          this.$refs.dynamicHeader.hide()
          this.$Message.success('设置成功')
        })
      },
    }
  }
</script>
<style lang='scss' scoped>
  .summary_page {
    .label_warp {
      text-align: center;
      margin-bottom: 15px;
      background-color: rgba(254, 252, 236, 1);
      width: auto;
      line-height: 32px;
      padding: 0 10px;

      .tips {
        line-height: 32px;
        font-size: 14px;

        .tips_icon {
          font-size: 20px;
          color: #0f42a7;
          vertical-align: sub;
        }
      }
    }

  }
</style>